﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KnowlegeAssistant
{
    public partial class EditRole : Form
    {
        public enum ActionType { add, edit}

        private ActionType action_type;
        private Role role;

        public EditRole(ActionType action_type)
        {
            InitializeComponent();
            this.action_type = action_type;
            InitControlNames();
        }

        public EditRole(Role role, ActionType action_type)
        {
            InitializeComponent();
            this.action_type = action_type;
            this.role = role;
            this.rolename.Text = this.role.Name;
            InitControlNames();
        }

        private void InitControlNames()
        {
            if (this.action_type == ActionType.add)
            {
                this.Text = "AddRole";
                this.button1.Text = "Добавить";
            }
            else if (this.action_type == ActionType.edit)
            {
                this.Text = "EditRole";
                this.button1.Text = "Применить";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string role_name = this.rolename.Text.Trim();
            if (this.action_type == ActionType.add)
            {               
                RoleUtil.AddRole(role_name);
            }
            else if (this.action_type == ActionType.edit)
            {
                RoleUtil.EditRole(this.role.RoleID, role_name);
            }
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void EditSubject_Load(object sender, EventArgs e)
        {

        }
    }
}
